<script setup>
import { ref } from "vue";
import { ElInput, ElButton, ElForm, ElFormItem } from "element-plus";
import { useRouter } from "vue-router";

const router = useRouter();
const username = ref("");
const password = ref("");

const handleLogin = () => {
  console.log("登录:", { username: username.value, password: password.value });
  // 登录逻辑，直接跳转到仪表盘
  router.push('/dashboard');
};

const handleRegister = () => {
  console.log("注册");
  // 注册逻辑
};
</script>

<template>
  <div class="login-container">
    <!-- 背景装饰元素 -->
    <div class="bg-decoration">
      <div class="node"></div>
      <div class="node"></div>
      <div class="node"></div>
      <div class="node"></div>
      <div class="node"></div>
    </div>

    <!-- 登录表单 -->
    <div class="login-form-wrapper">
      <ElForm class="login-form" label-position="top">
        <h2 class="title">轻客管家</h2>

        <ElFormItem label="用户名">
          <ElInput v-model="username" placeholder="请输入用户名" />
        </ElFormItem>

        <ElFormItem label="密码">
          <ElInput
            v-model="password"
            type="password"
            placeholder="请输入密码"
            show-password
          />
        </ElFormItem>

        <div class="buttons">
          <ElButton type="primary" @click="handleLogin" class="login-btn"
            >登录</ElButton
          >
          <ElButton @click="handleRegister" class="register-btn">注册</ElButton>
        </div>
      </ElForm>
    </div>
  </div>
</template>

<style scoped>
.login-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  background-color: #f5f7fa;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* 背景装饰 */
.bg-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.node {
  position: absolute;
  background-color: rgba(160, 174, 192, 0.1);
  border-radius: 50%;
}

.node:nth-child(1) {
  width: 80px;
  height: 80px;
  top: 10%;
  left: 15%;
  box-shadow: 0 0 30px rgba(160, 174, 192, 0.2);
}

.node:nth-child(2) {
  width: 40px;
  height: 40px;
  top: 30%;
  left: 75%;
}

.node:nth-child(3) {
  width: 60px;
  height: 60px;
  bottom: 20%;
  left: 25%;
}

.node:nth-child(4) {
  width: 50px;
  height: 50px;
  bottom: 10%;
  right: 15%;
}

.node:nth-child(5) {
  width: 30px;
  height: 30px;
  top: 50%;
  right: 30%;
}

/* 登录表单 */
.login-form-wrapper {
  position: relative;
  z-index: 1;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 40px;
  width: 400px;
  margin: 0 auto;
}

.title {
  text-align: center;
  margin-bottom: 30px;
  color: #1f2937;
}

.buttons {
  display: flex;
  gap: 15px;
  margin-top: 20px;
}

.login-btn {
  flex: 1;
  background-color: #3b82f6;
  border-color: #3b82f6;
}

.login-btn:hover {
  background-color: #2563eb;
  border-color: #2563eb;
}

.register-btn {
  flex: 1;
  background-color: #f3f4f6;
  color: #6b7280;
  border-color: #e5e7eb;
}

.register-btn:hover {
  background-color: #e5e7eb;
}
</style>
